package com.example.juc.big_talk_concurrent.chapter2.article7.spuriouswakeup;

public class Client {

    public static void main(String[] args) {
        Product product = new Product();

        // 创建生产者的任务类对象
        Runnable produceRunnable = new Runnable() {
            // 要执行的任务
            public void run() {
                for (int i = 0; i < 10; i++) {
                    try {
                        product.produce();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        // 创建消费者的任务类对象
        Runnable consumeRunnable = new Runnable() {
            // 要执行的任务
            public void run() {
                for (int i = 0; i < 10; i++) {
                    try {
                        product.consume();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };

        Thread producer1 = new Thread(produceRunnable, "Producer 1");
        producer1.start();
        Thread producer2 = new Thread(produceRunnable, "Producer 2");
        producer2.start();
        Thread consumer1 = new Thread(consumeRunnable, "Consumer 1");
        consumer1.start();
        Thread consumer2 = new Thread(consumeRunnable, "Consumer 2");
        consumer2.start();
    }
}
